package com.winit.openapi.tms.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;
import com.winit.tms.spi.booking.WarehouseInRuleValueAddedAmountService;
import com.winit.tms.spi.booking.command.WarehouseInRuleValueAddedAmountQueryCommand;
import com.winit.tms.spi.booking.vo.WarehouseInRuleValueAddedAmountVo;

/**
 * 增值费用查询
 * 
 * @version <pre>
 * Author	Version		Date		Changes
 * ming.chen 	1.0  		2017-9-20 	Created
 * 
 * </pre>
 * @since 1.
 */
@Controller
@RequestMapping(value = "/tms/valueAddedAmount")
public class BookingValueAddedAmountController extends BaseController {

    @Resource
    private WarehouseInRuleValueAddedAmountService warehouseInRuleValueAddedAmountService;

    @RequestMapping(value = "/queryAddedAmount")
    public String queryAddedAmount(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        Object obj = requestMsg.getData();
        WarehouseInRuleValueAddedAmountQueryCommand command = null;
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            command = new WarehouseInRuleValueAddedAmountQueryCommand();
            command.setWarehouseCode(json.getString("warehouseCode"));
            command.setDeliveryWayType(json.getString("deliveryWayType"));
            command.setIsNightStay(json.getString("isNightStay"));
            if(json.containsKey("docType")){
                command.setDocType(json.getString("docType"));
            }
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        WarehouseInRuleValueAddedAmountVo valueAddedAmountVo = warehouseInRuleValueAddedAmountService.queryValueAddedAmount(command);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("actualAmount", valueAddedAmountVo.getActualAmount());
        responseMsg.setData(data);
        return SUCCESS;
    }
}
